<template>
  <div class="homeWrap">
    <el-container class="only-large-screen">
      <el-aside :class="{hideSideBar:toogleSideBar,showSideBar:!toogleSideBar}" style="width:200px">
        <!-- 默认 unique-opened属性是false，表示不展开-->
        <el-menu
          router
          unique-opened
          :default-active="$route.path.split('/').pop()"
          class="el-menu-demo"
        >
          <el-submenu index="0">
            <template slot="title">
              <i class="el-icon-setting"></i>
              <span class="menu-title">项目详情</span>
            </template>
            <el-menu-item index="index">
              <i class="menu-item-icon el-icon-minus"></i>基本信息
            </el-menu-item>

            <el-menu-item index="config" :disabled="this.changeAbleFlag">
              <i class="menu-item-icon el-icon-minus"></i>修改提交
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <!-- 没有加一个新的容器进来，根本没有办法左右分割，官网上也是这个做法-->
      <el-container class="only-large-screen2">
        <el-header class="content-header" height="6%">
          <i class="el-icon-s-grid header-icon" title="隐藏/显示侧边栏" @click="setToogleSideBar"></i>
          <span>结构实验大厅试验预约系统</span>
          <br />
          <span style="font-size:14px">当前项目：{{projectInfo.project_name}}</span>
          <i class="el-icon-switch-button header-icon" title="退出当前项目" @click="quitCurProject"></i>
        </el-header>
        <el-main class="set-height">
          <!-- 内部还有嵌套的组件 -->
          <keep-alive>
            <router-view class="router-container"></router-view>
          </keep-alive>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import { mapState, mapActions } from "vuex";
export default {
  data() {
    return {
      header: { menu: "项目详情", toPageName: "返回主页", to: "/" },
      footerInfoHight: "25%",
      setFooterInfoHightFlag: true,
      projectInfoIf: true,
      changeAbleFlag: true
    };
  },
  computed: {
    ...mapState(["toogleSideBar", "projectInfo"]) //映射需要的数据
  },
  methods: {
    ...mapActions(["setToogleSideBar", "setInitCurrentProjectInfo"]),

    quitCurProject() {
      this.$router.push("/home");
    },
    setFooterInfoHigh() {
      if (this.setFooterInfoHightFlag) {
        this.footerInfoHight = "0%";
        this.setFooterInfoHightFlag = false;
        this.projectInfoIf = false;
      } else {
        this.footerInfoHight = "25%";
        this.setFooterInfoHightFlag = true;
        this.projectInfoIf = true;
      }
    }
  },
  created() {
    //这个id还是需要的，它是区分项目的，不是区分用户的，
    //但是判断授权就不用判断了，直接就在后端利用token拦截就行了
    let id = this.$route.params.id;
    this.$http
      .get(`project/getProjectInfoByTokenAndId?info=` + id)
      .then(res => {
        if (res.data.code == 200) {
          this.setInitCurrentProjectInfo(res.data.data);
          if (this.projectInfo.status == 1) {
            this.changeAbleFlag = true;
          } else {
            this.changeAbleFlag = false;
          }
        }
      });
  }
};
</script>

<style lang="scss" scoped>
.homeWrap {
  // background-color: blue;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;

  .only-large-screen {
    // background-color: yellow;
    height: 100%;
    @media screen and (max-width: 500px) {
      // display: none;
    }
    .hideSideBar {
      animation: hideSideBar 0.5s forwards;
    }
    .showSideBar {
      animation: showSideBar 0.5s forwards;
    }
    .el-aside {
      background-color: rgb(238, 241, 246);

      .menu-title {
        font-weight: 600;
      }
      .menu-item-icon {
        font-size: 12px;
      }
    }
  }
  .only-large-screen2 {
    // background-color: blue;
    .content-header {
      background-color: lightcyan;
      line-height: 30px;
      text-align: center;
      border-bottom: 2px solid #dcdfe6;
      .el-icon-s-grid {
        float: left;
        line-height: 30px;
      }
      .el-icon-switch-button {
        float: right;
        line-height: 30px;
      }
      .header-icon {
        color: #409eff;
        cursor: pointer;
      }
      span {
        font-size: 18px;
      }
    }
    .el-main {
      padding: 0;
      padding-top: 10px;

      .router-container {
        padding: 0px;
        // height: 90vh;
        // overflow: hidden;
      }
    }
  }
  @keyframes hideSideBar {
    from {
    }
    to {
      width: 0;
    }
  }
  @keyframes showSideBar {
    from {
      width: 0;
    }
    to {
    }
  }
  .only-small-screen {
    display: none;
    @media screen and (max-width: 500px) {
      display: block;
    }
    .set-height {
      text-align: center;
      color: #909399;
      div {
        margin-top: 5em;
      }
    }
  }
}
</style>